home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / workbench / term_4.8 / extras / source / gtlayout-source.lha / LTP_MakeItem.c < prev    next >
C/C++ Source or Header  |  1997-05-08  |  3KB  |  129 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1997 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #include "Assert.h"
  15.  
  16. #ifdef DO_MENUS
  17.  
  18.     /* LTP_MakeItem(RootMenu *Root,struct NewMenu *Template):
  19.      *
  20.      *    Create a single menu item and fill it in.
  21.      */
  22.  
  23. ItemNode *
  24. LTP_MakeItem(RootMenu *Root,struct NewMenu *Template)
  25. {
  26.     ItemNode    *Item;
  27.     LONG         Size;
  28.  
  29.         // Which type of entry to create
  30.  
  31.     if(Template->nm_Label == NM_BARLABEL)
  32.         Size = sizeof(ItemNode) + sizeof(struct Image);
  33.     else
  34.         Size = sizeof(ItemNode) + sizeof(struct IntuiText);
  35.  
  36.         // Make room for it
  37.  
  38.     if(Item = AsmAllocPooled(Root->Pool,Size,SysBase))
  39.     {
  40.             // Is it a separator bar?
  41.  
  42.         if(Template->nm_Label == NM_BARLABEL)
  43.         {
  44.             struct Image *Image = (struct Image *)(Item + 1);
  45.  
  46.                 // Fill in the image data
  47.  
  48.             Image->LeftEdge        = 2;
  49.             Image->TopEdge        = 2;
  50.             Image->Depth        = Root->DrawInfo->dri_Depth;
  51.             Image->PlaneOnOff    = Root->TextPen;
  52.             Image->Height        = 2;
  53.  
  54.                 // Now take care of the item itself
  55.  
  56.             Item->Item.ItemFill = Image;
  57.             Item->Item.Width    = 2;
  58.             Item->Item.Height    = 2 + Image->Height + 2;
  59.             Item->Flags            = ITEMF_IsBar;
  60.             Item->Item.Flags    = HIGHNONE;
  61.         }
  62.         else
  63.         {
  64.             struct IntuiText *IntuiText = (struct IntuiText *)(Item + 1);
  65.  
  66.                 // Fill in the label
  67.  
  68.             LTP_InitIText(Root,IntuiText);
  69.  
  70.             IntuiText->LeftEdge    = 2;
  71.             IntuiText->TopEdge    = (Root->ItemHeight - Root->RPort.TxHeight) / 2;
  72.             IntuiText->IText    = Template->nm_Label;
  73.  
  74.                 // Now take care of the item itself
  75.  
  76.             Item->Item.ItemFill    = IntuiText;
  77.             Item->Item.Width    = 2 + TextLength(&Root->RPort,IntuiText->IText,strlen(IntuiText->IText)) + 2;
  78.             Item->Item.Height    = Root->ItemHeight;
  79.             Item->Item.Flags    = ITEMTEXT | HIGHCOMP;
  80.  
  81.                 // Is there a command to take care of?
  82.  
  83.             if(Template->nm_CommKey)
  84.             {
  85.                     // Special command?
  86.  
  87.                 if(Template->nm_Flags & NM_COMMANDSTRING)
  88.                 {
  89.                     Item->ExtraLabel    = Template->nm_CommKey;
  90.                     Item->Flags            = ITEMF_Command;
  91.                 }
  92.                 else
  93.                 {
  94.                     DB(kprintf("commkey 0x%08lx\n",Template->nm_CommKey));
  95.  
  96.                         // Just put in the usual command sequence in there
  97.  
  98.                     Item->Item.Flags    |= COMMSEQ;
  99.                     Item->Item.Command     = (BYTE)ToUpper(Template->nm_CommKey[0]);
  100.                 }
  101.             }
  102.  
  103.                 // Move up for the checkmark
  104.  
  105.             if(Template->nm_Flags & CHECKIT)
  106.                 Item->Item.Width += 2 + Root->CheckWidth;
  107.  
  108.                 // Disable the item if necessary
  109.  
  110.             if(!(Template->nm_Flags & NM_ITEMDISABLED))
  111.                 Item->Item.Flags |= ITEMENABLED;
  112.  
  113.                 // Fill in the rest of the flags
  114.  
  115.             Item->Item.Flags |= Template->nm_Flags & (CHECKIT | MENUTOGGLE | CHECKED);
  116.  
  117.                 // Take care of the remaining data
  118.  
  119.             Item->Item.MutualExclude = Template->nm_MutualExclude;
  120.         }
  121.  
  122.         Item->UserData = Template->nm_UserData;
  123.     }
  124.  
  125.     return(Item);
  126. }
  127.  
  128. #endif    /* DO_MENUS */
  129.